/**
 *
 */
package jp.seraph.same.view.cui;

import jp.seraph.cui.AbstractCommand;
import jp.seraph.cui.InternalConsole;
import jp.seraph.cui.StringDataType;
import jp.seraph.cui.SystemNode;
import jp.seraph.cui.SystemNodeType;
import jp.seraph.same.message.MessageUtil;

/**
 *
 *
 */
public class CreateMotionSessionCommand extends AbstractCommand {

    /**
     * @param aParent
     * @param aConsole
     */
    public CreateMotionSessionCommand(MotionData aParent, InternalConsole aConsole) {
        super(aParent, aConsole);
    }

    /**
     *
     * @see jp.seraph.cui.AbstractCommand#executeImpl(jp.seraph.cui.SystemNode[], int)
     */
    @Override
    protected void executeImpl(SystemNode[] aArgs, int aArgListIndex) {
        MotionData tParent = (MotionData)this.getParent();

        if(aArgListIndex == 0){
            tParent.addSession();
        }else{
            int tNewIndex = Integer.parseInt(aArgs[0].toString());
            if(tNewIndex < 0)
                throw new RuntimeException(MessageUtil.cannotUseNegativeInteger());

            tParent.createSession(tNewIndex);
        }
    }

    /**
     *
     * @see jp.seraph.cui.Command#getArgumentTypes()
     */
    public SystemNodeType[][] getArgumentTypes() {
        SystemNodeType[][] tResult = new SystemNodeType[2][];

        tResult[0] = new SystemNodeType[0];
        tResult[1] = new SystemNodeType[]{StringDataType.getInstance()};

        return tResult;
    }

    /**
     *
     * @see jp.seraph.cui.Command#getHelp()
     */
    public String getHelp() {
        return "create \"SessionNumber\" : create a new Session";
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#getName()
     */
    public String getName() {
        return "create";
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#getType()
     */
    public SystemNodeType getType() {
        return CreateMotionSessionCommandType.getInstance();
    }

    /**
     *
     * @see jp.seraph.cui.SystemNode#isRoot()
     */
    public boolean isRoot() {
        return false;
    }
}
